from itertools import chain
from dateutil.relativedelta import relativedelta
import requests
import common.config
from common.config import *
from common.mysql_db_data import MysqlDbTriton


class DataBoard:
    def mallSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/util/query/mallSelect"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[]}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('商场名称',r.json())
        return r.json()

    def macSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/util/query/macSelect"
        param={"mallIds":["521f07c16038b51301000001"]}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('点位mac',r.json())
        return r.json()

    def getCameraflowDaily(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getCameraflowDaily"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["521f07c16038b51301000001"],"terminalMacs":["cc:4b:73:58:14:34"],"startDt":"2020-02-25","endDt":"2020-03-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('摄像头日数据',r.json())
        return r.json()

    def getwifiMacDaily(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getwifiMacDaily"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["521f07c16038b51301000001"],"terminalMacs":["cc:4b:73:58:14:34"],"startDt":"2020-02-25","endDt":"2020-03-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('wifi日数据',r.json())
        return r.json()

    def getRfidDaily(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getRfidDaily"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["5b9b5b51130b38000b3975a9"],"terminalMacs":["cc:4b:73:2b:4f:8a"],"startDt":"2020-02-25","endDt":"2020-03-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('Rfid日数据',r.json())
        return r.json()

    def getInfraredDaily(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getInfraredDaily"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["5b9b5b51130b38000b3975a9"],"terminalMacs":["cc:4b:73:2b:4f:8a"],"startDt":"2020-02-25","endDt":"2020-03-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('Infrared日数据',r.json())
        return r.json()

    def getCameraflowCurdate(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getCameraflowCurdate"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["521f07c16038b51301000001"],"terminalMacs":["cc:4b:73:57:df:06"],"startDt":"2020-05-08","endDt":"2020-05-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('摄像头当日数据',r.json())
        return r.json()

    def getwifiMacCurdate(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getwifiMacCurdate"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["521f07c16038b51301000001"],"terminalMacs":["cc:4b:73:57:df:06"],"startDt":"2020-05-08","endDt":"2020-05-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('wifi当日数据',r.json())
        return r.json()

    def getInfraredCurdate(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getInfraredCurdate"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["521f07c16038b51301000001"],"terminalMacs":["cc:4b:73:57:df:06"],"startDt":"2020-05-08","endDt":"2020-05-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('Infrared当日数据',r.json())
        return r.json()

    def getRfidCurdate(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/device/getRfidCurdate"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["521f07c16038b51301000001"],"terminalMacs":["cc:4b:73:57:df:06"],"startDt":"2020-05-08","endDt":"2020-05-08"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('Rfid当日数据',r.json())
        return r.json()

    def appVersionSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/util/query/appVersionSelect"
        param={"appId":"com.rongyi.sflcustomized"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('app版本号',r.json())
        return r.json()

    def appPageSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/util/query/appPageSelect"
        param={"appId":"com.rongyi.sflcustomized","appVersions":["3.10.04.000"]}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('页面名称',r.json())
        return r.json()

    def getPageDaily(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/app/getPageDaily"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["5d3045ee130b38000ab41ba3"],"terminalMacs":["cc:4b:73:2b:5b:24"],"appVersions":["3.10.04.000"],"pageNames":["PAGE_PAYMENT_RESULT","PAGE_SCAN_PAYMENT","PAGE_SEARCH_RESULT","PAGE_SEARCH_VOICE","PAGE_SHOPPING_CAT","PAGE_COMMUNITY_DETAIL","PAGE_COMMUNITY_INDEX","PAGE_INDEX","PAGE_LVL2_CATEGORY_LIST","PAGE_ORDER_COMMIT","PAGE_PAYMENT_CHOICE","PAGE_BRAND_LIST","PAGE_COMMODITY_DETAIL","PAGE_COMMODITY_LIST","PAGE_COMMODITY_SPEC","PAGE_BRAND_HISTORY"],"appId":"com.rongyi.sflcustomized","startDt":"2020-02-21","endDt":"2020-03-22"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('页面分析日数据',r.json())
        return r.json()

    def getElementDaily(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/app/getElementDaily"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["5d3045ee130b38000ab41ba3"],"terminalMacs":["cc:4b:73:2b:5b:24"],"appVersions":["3.10.04.000"],"pageNames":["PAGE_PAYMENT_RESULT","PAGE_SCAN_PAYMENT","PAGE_SEARCH_RESULT","PAGE_SEARCH_VOICE","PAGE_SHOPPING_CAT","PAGE_COMMUNITY_DETAIL","PAGE_COMMUNITY_INDEX","PAGE_INDEX","PAGE_LVL2_CATEGORY_LIST","PAGE_ORDER_COMMIT","PAGE_PAYMENT_CHOICE","PAGE_BRAND_LIST","PAGE_COMMODITY_DETAIL","PAGE_COMMODITY_LIST","PAGE_COMMODITY_SPEC","PAGE_BRAND_HISTORY"],"appId":"com.rongyi.sflcustomized","startDt":"2020-02-21","endDt":"2020-03-22"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('元素分析日数据',r.json())
        return r.json()

    def getPageCurdate(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/app/getPageCurdate"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["5d3045ee130b38000ab41ba3"],"terminalMacs":["cc:4b:73:2b:5b:24"],"appVersions":["3.10.04.000"],"pageNames":["PAGE_PAYMENT_RESULT","PAGE_SCAN_PAYMENT","PAGE_SEARCH_RESULT","PAGE_SEARCH_VOICE","PAGE_SHOPPING_CAT","PAGE_COMMUNITY_DETAIL","PAGE_COMMUNITY_INDEX","PAGE_INDEX","PAGE_LVL2_CATEGORY_LIST","PAGE_ORDER_COMMIT","PAGE_PAYMENT_CHOICE","PAGE_BRAND_LIST","PAGE_COMMODITY_DETAIL","PAGE_COMMODITY_LIST","PAGE_COMMODITY_SPEC","PAGE_BRAND_HISTORY"],"appId":"com.rongyi.sflcustomized","startDt":"2020-02-21","endDt":"2020-03-22"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('页面分析当日数据',r.json())
        return r.json()

    def getElementCurdate(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "triton/dashboard/app/getElementCurdate"
        param={"provinceIds":["51f9d7f231d6559b7d000001"],"cityIds":[],"districtIds":[],"mallIds":["5d3045ee130b38000ab41ba3"],"terminalMacs":["cc:4b:73:2b:5b:24"],"appVersions":["3.10.04.000"],"pageNames":["PAGE_PAYMENT_RESULT","PAGE_SCAN_PAYMENT","PAGE_SEARCH_RESULT","PAGE_SEARCH_VOICE","PAGE_SHOPPING_CAT","PAGE_COMMUNITY_DETAIL","PAGE_COMMUNITY_INDEX","PAGE_INDEX","PAGE_LVL2_CATEGORY_LIST","PAGE_ORDER_COMMIT","PAGE_PAYMENT_CHOICE","PAGE_BRAND_LIST","PAGE_COMMODITY_DETAIL","PAGE_COMMODITY_LIST","PAGE_COMMODITY_SPEC","PAGE_BRAND_HISTORY"],"appId":"com.rongyi.sflcustomized","startDt":"2020-02-21","endDt":"2020-03-22"}
        header = {"Content-Type": "application/json;charset=UTF-8"}
        r = requests.post(url,data=json.dumps(param),headers=header)
        #print('元素分析当日数据',r.json())
        return r.json()



#a=DataBoard()
#a.getElementDaily('test')